/**
 * 生成唯一id
 * @returns 
 */
export function getPrimaryKey(){
    let timestamp =new Date().getTime()
    let randomNumber=Math.floor(Math.random()*10000);
    let primaryKey=(timestamp+''+randomNumber)*1;
    return primaryKey
}    

/**
 * 上移几个
 * @param dataList 数组
 * @param position 位置
 * @param number 移动数量 默认1
 */
export function handleTop(dataList,position,number=1,isSub=false){
    let index=isSub?position-1:position
    if (index >0) {
        let localDataList = dataList;
        localDataList[index] = localDataList.splice(index-1, number, localDesignData[index])[0];
        dataList = [...localDataList];
        position = index-1
    }
}

/**
 * 下移几个
 * @param dataList 数组
 * @param position 位置
 * @param number 移动数量 默认1
 */
export function handleBottom(dataList,position,number=1,isSub=false){
    let index=isSub?position-1:position
    if (index<(designData.value.length-1)) {
        let localDataList = dataList;
        localDataList[index] = localDataList.splice(index+1, number, localDesignData[index])[0];
        dataList = [...localDataList];
        position = isSub?position+2:position+1
    }
}

/**
 * 插入一个对象
 * @param dataList 数组
 * @param position 位置
 * @param item 插入对象
 */
export function handleInsert(dataList,position,item) {
    dataList.splice(position, 0, item)
}

/**
 * 删除某个位置的对象
 * @param {*} dataList 数组
 * @param {*} position 位置
 * @param {*} number 删除数量 默认1
 */
export function handleRemove(dataList,position,number=1) {
    dataList.splice(position, number)
    let maxIndex = dataList.length - number
    if (position > maxIndex||maxIndex <0) {
        position = maxIndex
    }
}